package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.School;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SchoolDAO{
	
	@SQL("SELECT * FROM School WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<School> query(@SQLParam("t") School school);
	
	@SQL("SELECT count(1) FROM School WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ")
    int querysize(@SQLParam("t") School school);
	
	@SQL("SELECT * FROM School WHERE deleteFlag=1 ORDER BY areaId,id ")
    List<School> queryAll();
	
    @SQL("select * from School where id=:1")
    School queryById(int id);
    
    @SQL("INSERT INTO School (areaId,code,name,address,num,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.areaId,:t.code,:t.name,:t.address,:t.num,1,now(),:t.createUser,now(),:t.updateUser)")
    void create(@SQLParam("t") School school);
	
	@SQL("UPDATE School SET areaId=:t.areaId,code=:t.code,name=:t.name,address=:t.address,num=:t.num,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") School school);
	
	@SQL("UPDATE School SET num=num+:2 WHERE id=:1")
    void updateNumById(int id,int num);
    
    @SQL("UPDATE School SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("select id,areaId,name from School where deleteFlag=1")
	List<Map> asSchoolEnum();
}
